<template>
	<view class="fireFacilities ff-font-14">
		<view class="fireFacilities-content">
			<view class="fireFacilities-content-title ff-bg-fff ff-border-radius-5">
				<view
					class="fireFacilities-content-box-title ff-padding-bottom-15 ff-font-16 ff-font-weight-600 ff-border-bottom">
					维保设施</view>
				<view v-if="fireFacilitiesList.length < 1"
					class="ff-bg-fff ff-padding-top-15 ff-padding-left-5 ff-padding-bottom-30">暂无维保设施</view>
			</view>
			<view>
				<view v-if="fireFacilitiesList.length > 0">
					<view v-for="(item, index) of fireFacilitiesList" :key="index"
						class="fireFacilities-content-box ff-font-15 ff-bg-fff ff-border-radius-5 ff-solid-bottom ff-line-height-1-3">
						<view class="fireFacilities-content-box-title ff-font-15 ff-font-weight-600 ff-flex-between"
							@click="cuIconClick(index)">
							<view :class="{ 'ff-color-blue': item.showCount }">
								{{ index + 1 }}.&nbsp;{{ item.facilitiesItemName }}
							</view>
							<view>
								<view v-if="!item.showCount"><u-icon name="arrow-down" color="#0B204B"
										size="36"></u-icon></view>
								<view v-else><u-icon name="arrow-up" color="#3178FF" size="36"></u-icon></view>
							</view>
						</view>
						<view v-if="item.showCount" class="ff-font-14">
							<view class="ff-padding-top-17 ff-border-bottom ff-padding-bottom-17 ff-flex-between">
								<view>保养内容</view>
								<view class="ff-color-222">
									{{ item.facilitiesItemContent == null ? '/' : item.facilitiesItemContent }}
								</view>
							</view>
							<view class="ff-padding-top-17 ff-border-bottom ff-padding-bottom-17 ff-flex-between">
								<view>部位</view>
								<view class="ff-color-222">{{ item.position == null ? '/' : item.position }}</view>
							</view>
							<view class="ff-padding-top-17 ff-border-bottom ff-padding-bottom-17 ff-flex-between">
								<view>总数</view>
								<view class="ff-color-222">{{ item.number == null ? '/' : item.number }}</view>
							</view>
							<view class="ff-padding-top-17 ff-border-bottom ff-padding-bottom-17 ff-flex-between">
								<view>抽查数量</view>
								<view class="ff-color-222">{{ item.checkNum == null ? '/' : item.checkNum }}</view>
							</view>
							<view class="ff-padding-top-17 ff-border-bottom ff-padding-bottom-17">
								<view class="ff-margin-bottom-15">问题/建议</view>
								<textarea v-model="item.problem" :class="{textareaHeight:autoHeight}"
									:auto-height="autoHeight" :disabled="true" maxlength="-1"
									class="ff-color-222 ff-border-radius-10" />
							</view>
							<view
								class="ff-padding-top-17 ff-border-bottom ff-padding-bottom-17 ff-flex-between ff-align-items-one">
								<view>结果</view>
								<u-radio-group v-model="item.checkResult">
									<u-radio v-for="(items, ind) of radioList" :disabled="items.id !== item.checkResult"
										:key="ind" :name="items.id">{{ items.name }}</u-radio>
								</u-radio-group>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="fireFacilities-imgBox ff-padding-10 ff-margin-10 ff-bg-fff ff-border-radius-5">
			<view
				class="fireFacilities-content-box-title ff-margin-bottom-15 ff-font-16 ff-font-weight-600 ff-padding-bottom-10 ff-border-bottom">
				执业过程</view>
			<view>
				<view v-if="fireImgList.length > 0">
					<u-row gutter="20">
						<u-col span="3" v-for="(item, index) of fireImgList" :key="index">
							<view class="fireFacilities-imgBox-img ff-margin-bottom-10" @click="previewClick(item)">
								<image :src="item" mode="" />
							</view>
						</u-col>
					</u-row>
				</view>
				<view class="ff-color-999 ff-margin-top-10 ff-padding-left-5 ff-font-14 ff-padding-bottom-30" v-else>
					暂无执业图片</view>
			</view>
		</view>
		<u-back-top :scrollTop="scrollTopList.scrollTop" top="200" mode="circle" :iconStyle="scrollTopList.iconStyle"
			:customStyle="scrollTopList.customstyle"></u-back-top>
		<u-toast ref="uToast" />
		<f-loading ref="loading" />
	</view>
</template>

<script>
	export default {
		name: 'fireFacilities',
		data() {
			return {
				autoHeight: false, // textarea高度
				// 返回顶部组件参数
				scrollTopList: {
					scrollTop: 0,
					iconStyle: {
						fontSize: '32rpx',
						color: '#FFFFFF'
					},
					customstyle: {
						background: '#3B83FE'
					}
				},
				radioList: [{
						name: '正常',
						id: 0
					},
					{
						name: '异常',
						id: 1
					}
				],
				fireFacilitiesList: [], // 消防设施列表
				fireImgList: [] // 执业图片
			};
		},
		onPageScroll(e) {
			this.scrollTopList.scrollTop = e.scrollTop;
		},
		onLoad(e) {
			this.getTelInfo() // 获取机型
			this.getFireFacilitiesList(e.id); // 获取消防设施列表
			this.getFireImgList(e.id); // 获取执业图片
		},
		methods: {
			// 获取当前手机信息
			getTelInfo() {
				let that = this
				uni.getSystemInfo({
					success: function(res) {
						// console.log('当前机型信息', res.deviceBrand)
						if (res.deviceBrand == 'vivo') {
							that.autoHeight = false
						} else {
							that.autoHeight = true
						}
					}
				});
			},
			// 获取消防设施列表
			async getFireFacilitiesList(id) {
				this.$refs.loading.openLoading('加载中···');
				const data = await this.$http.post({
					url: `/maintenance/maintenance/facilities/${id}/items`
				});
				// console.log('获取消防设施列表-----', data);
				if (data.code == 200) {
					this.fireFacilitiesList = data.data;
					this.fireFacilitiesList.forEach(item => {
						this.$set(item, 'showCount', true);
					});
				}
				this.$refs.loading.closeLoading();
			},
			// 点击展开和收起消防设施
			cuIconClick(idx) {
				this.fireFacilitiesList[idx].showCount = !this.fireFacilitiesList[idx].showCount;
			},
			// 获取执业图片
			async getFireImgList(id) {
				this.$refs.loading.openLoading('加载中···');
				const data = await this.$http.post({
					url: `/maintenance/maintenance/facilities/${id}/attach`
				});
				// console.log('获取执业图片-----', data);
				if (data.code == 200) {
					this.fireImgList = data.data;
				}
				this.$refs.loading.closeLoading();
			},
			// 预览测试打印条的照片
			previewClick(img) {
				uni.previewImage({
					urls: this.fireImgList,
					current: img
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.fireFacilities {
		&-content {
			&-title {
				padding: 30rpx 20rpx 10rpx;
				margin: 20rpx 20rpx 0;
			}

			&-box {
				margin: 0 20rpx;
				padding: 30rpx;

				&-title {
					color: #0B204B;
				}

				.ff-border-bottom view:first-child {
					color: #0B204B;
				}

				.ff-border-bottom view:last-child {
					width: 400rpx;
					text-align: right;
				}
			}
		}

		&-imgBox {
			padding: 30rpx 20rpx;
			margin-bottom: 60rpx;

			&-img {
				image {
					width: 100%;
					height: 140rpx;
				}
			}
		}

		textarea {
			background-color: #F8F8F9;
			padding: 25rpx;
			min-height: 150rpx !important;
			width: 93%;
		}
	}

	.textareaHeight {
		height: 200rpx;
	}
</style>